//
//  TimeClockViewController.m
//  Qihuo
//
//  Created by Vencoo on 13-12-18.
//  Copyright (c) 2013年 Vencoo. All rights reserved.
//

#import "TimeClockViewController.h"
@interface TimeClockViewController ()
{
    ASIFormDataRequest *obtainFloor;
    UIScrollView *bgScrollView;
}
@end

@implementation TimeClockViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
- (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBar.hidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated
{
    self.navigationController.navigationBar.hidden = NO;
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    NSURL *queryUrl = [NSURL URLWithString:timeClock];
    obtainFloor = [ASIFormDataRequest requestWithURL:queryUrl];
    [obtainFloor setPostValue:[NSString stringWithFormat:@"%d",[Appinfomation shareIstance].strongXunJianCount] forKey:@"isNormal"];
    [obtainFloor startSynchronous];
    NSString *response = [obtainFloor responseString];
    NSDictionary *queryDic = [response JSONValue];
    NSArray *queryDataArr = [queryDic objectForKey:@"data"];
    NSLog(@"查询%@",queryDataArr);
    
    [self initUIWithArray:queryDataArr];
    [Appinfomation shareIstance].strongXunJianCount = 110;
}
- (void)initUIWithArray:(NSArray *)dataArray
{
    BlackbackgroundView *blackGroundV = [[BlackbackgroundView alloc]initWithFrame:CGRectMake(0, 0, scrennWidth, screenHeight)];
    [self.view addSubview:blackGroundV];
    blackGroundV.userInteractionEnabled = YES;
    blackGroundV.delegate = self;

    bgScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(10, 10, [Appinfomation shareIstance].whiteView.frame.size.width - 20, [Appinfomation shareIstance].whiteView.frame.size.height - 20)];
    bgScrollView.scrollEnabled = YES;
    [[Appinfomation shareIstance].whiteView addSubview:bgScrollView];
    UILabel *titleLb = [UILabel new];
    if ([Appinfomation shareIstance].strongXunJianCount == 0)
    {
        titleLb.text = @"正常开放日巡检表";
    }
    else if ([Appinfomation shareIstance].strongXunJianCount == 1)
    {
        titleLb.text = @"非正常开放日巡检表";
    }

    titleLb.font = [UIFont systemFontOfSize:35];
    titleLb.backgroundColor = [UIColor clearColor];
    CGSize sz = [titleLb.text sizeWithFont:titleLb.font constrainedToSize:CGSizeMake(MAXFLOAT, 40)];
    titleLb.frame = CGRectMake((blackGroundV.frame.size.width - sz.width)/2, 80, sz.width, sz.height);
    [blackGroundV addSubview:titleLb];

    for (int i = 0; i < dataArray.count; i ++)
    {
        NSDictionary *dataDic = [dataArray objectAtIndex:i];
        UILabel *timeLb = [UILabel new];
        timeLb.text = [dataDic objectForKey:@"date"];
        timeLb.font = [UIFont systemFontOfSize:30];
        CGSize mySz = [timeLb.text sizeWithFont:timeLb.font constrainedToSize:CGSizeMake(MAXFLOAT, 40)];
        timeLb.frame = CGRectMake(40, 10 + (mySz.height + interval111)*i, mySz.width, mySz.height);
        [bgScrollView addSubview:timeLb];
        
        UILabel *addressLb = [UILabel new];
        addressLb.text = [dataDic objectForKey:@"address"];
        addressLb.font = [UIFont systemFontOfSize:30];
        mySz = [addressLb.text sizeWithFont:addressLb.font constrainedToSize:CGSizeMake(MAXFLOAT, 40)];
        addressLb.frame = CGRectMake(timeLb.frame.origin.x + timeLb.frame.size.width + interval111 * 5, timeLb.frame.origin.y, mySz.width, mySz.height);
        [bgScrollView addSubview:addressLb];
        bgScrollView.contentSize = CGSizeMake(self.bgDelegate.whiteView.frame.size.width - 20, addressLb.frame.origin.y + addressLb.frame.size.height);
    }
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
